package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.SeacraftSouthSeaCommonMgr;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftSouthSeaMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;

/**
 * @Description
 * @Author cwq
 * @Data 2022/2/12 16:51
 */
@Cmd(code = GameProtocol.S_SEACRAFT_SOUTH_SEA_BUY_BUFF_FROM_CROSS, desc = "海上争霸 南海丝路 购买buff  跨服返回区服 协议")
public class SeacraftSouthSeaBuyBuffFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffCrossToGameMsg reqMsg = SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffCrossToGameMsg.parseFrom(packet.getBytes());
        Property property = new Property(GameConfig.GAME_MONEY_INGOTS, reqMsg.getPreReduceCount());
        player.getModule(PreReduceModule.class).restorePreReduce(property);
        SeacraftSouthSeaProto.SeacraftSouthSeaBuyBuffRespMsg stcMsg = reqMsg.getStcMsg();
        if(stcMsg.getRet() == 0){
            // 扣道具
            Property consume = new Property(GameConfig.GAME_MONEY_INGOTS,stcMsg.getCostNum());
            player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.SeacraftActivity, eLogMoneyType.SeacraftActivityBuyBuffCost);
        }
        player.sendPacket(ClientProtocol.U_SEACRAFT_SOUTH_SEA_BUY_BUFF,stcMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
